home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)P / (A)P1.ADF / Polygon / poly.c < prev    next >
C/C++ Source or Header  |  1987-05-25  |  4KB  |  155 lines

  1. /* poly.c -- precompute x,y coordinates to speed drawing */
  2.  
  3. #include "lattice/stdio.h"
  4. #include "lattice/math.h"
  5.  
  6. short int x1[50][15];
  7. short int x2[50][27];
  8. short int x3[50][51];
  9. short int y1[50][15];
  10. short int y2[50][27];
  11. short int y3[50][51];
  12.  
  13. main()
  14. {
  15.    register short int a,i,l,ls,n1,s;
  16.    double an,n;
  17.    FILE *fp;
  18.  
  19.    for (a=0;a<50;a++){
  20.       ls=a+1;
  21.       for (i=0;i<3;i++){
  22.          switch (i) {
  23.             case 0:
  24.                an=PI/2.0;
  25.                s=0;
  26.                for (l=10;l<=20;l+=5){
  27.                   x1[a][s]=(l*ls)/10;
  28.                   y1[a][s]=0;
  29.                   ++s;
  30.                   for (n=an;n<=(2*PI+.001);n+=an){
  31.                      x1[a][s]=(short int)(l*(ls*cos(n))/10);
  32.                      y1[a][s]=(short int)(ls*sin(n));
  33.                      s++;
  34.                   }
  35.                }
  36.                break;
  37.             case 1:
  38.                an=PI/4.0;
  39.                s=0;
  40.                for (l=10;l<=20;l+=5){
  41.                   x2[a][s]=(l*ls)/10;
  42.                   y2[a][s]=0;
  43.                   ++s;
  44.                   for (n=an;n<=(2*PI+.001);n+=an){
  45.                      x2[a][s]=(short int)(l*(ls*cos(n))/10);
  46.                      y2[a][s]=(short int)(ls*sin(n));
  47.                      s++;
  48.                   }
  49.                }
  50.                break;
  51.             case 2:
  52.                an=PI/8.0;
  53.                s=0;
  54.                for (l=10;l<=20;l+=5){
  55.                   x3[a][s]=(l*ls)/10;
  56.                   y3[a][s]=0;
  57.                   ++s;
  58.                   for (n=an;n<=(2*PI+.001);n+=an){
  59.                      x3[a][s]=(short int)(l*(ls*cos(n))/10);
  60.                      y3[a][s]=(short int)(ls*sin(n));
  61.                      s++;
  62.                   }
  63.                }
  64.                break;
  65.          }
  66.       }
  67.    }
  68.    fp = fopen("polynums.c","w");
  69.    fprintf (fp,"short int x1[50][15] = {\n\n");
  70.    for (a=0;a<50;a++){
  71.       if (a!=0)
  72.          fprintf(fp,"\t},\n\n");
  73.       fprintf(fp,"\t{\n");
  74.       for (n1=0;n1<15;n1++){
  75.          fprintf(fp,"\t%d",x1[a][n1]);
  76.          if (n1!=14)
  77.             fprintf(fp,",");
  78.          if (n1 % 7 == 6)
  79.             fprintf(fp,"\n");
  80.       }
  81.    }
  82.    fprintf (fp,"\t}\n};\n\n");
  83.    fprintf (fp,"short int y1[50][15] = {\n\n");
  84.    for (a=0;a<50;a++){
  85.       if (a!=0)
  86.          fprintf(fp,"\t},\n\n");
  87.       fprintf(fp,"\t{\n");
  88.       for (n1=0;n1<15;n1++){
  89.          fprintf(fp,"\t%d",y1[a][n1]);
  90.          if (n1!=14)
  91.             fprintf(fp,",");
  92.          if (n1 % 7 == 6)
  93.             fprintf(fp,"\n");
  94.       }
  95.    }
  96.    fprintf (fp,"\t}\n};\n\n");
  97.    fprintf (fp,"short int x2[50][27] = {\n\n");
  98.    for (a=0;a<50;a++){
  99.       if (a!=0)
  100.          fprintf(fp,"\t},\n\n");
  101.       fprintf(fp,"\t{\n");
  102.       for (n1=0;n1<27;n1++){
  103.          fprintf(fp,"\t%d",x2[a][n1]);
  104.          if (n1!=26)
  105.             fprintf(fp,",");
  106.          if (n1 % 7 == 6)
  107.             fprintf(fp,"\n");
  108.       }
  109.    }
  110.    fprintf (fp,"\t}\n};\n\n");
  111.    fprintf (fp,"short int y2[50][27] = {\n\n");
  112.    for (a=0;a<50;a++){
  113.       if (a!=0)
  114.          fprintf(fp,"\t},\n\n");
  115.       fprintf(fp,"\t{\n");
  116.       for (n1=0;n1<27;n1++){
  117.          fprintf(fp,"\t%d",y2[a][n1]);
  118.          if (n1!=26)
  119.             fprintf(fp,",");
  120.          if (n1 % 7 == 6)
  121.             fprintf(fp,"\n");
  122.       }
  123.    }
  124.    fprintf (fp,"\t}\n};\n\n");
  125.    fprintf (fp,"short int x3[50][51] = {\n\n");
  126.    for (a=0;a<50;a++){
  127.       if (a!=0)
  128.          fprintf(fp,"\t},\n\n");
  129.       fprintf(fp,"\t{\n");
  130.       for (n1=0;n1<51;n1++){
  131.          fprintf(fp,"\t%d",x3[a][n1]);
  132.          if (n1!=50)
  133.             fprintf(fp,",");
  134.          if (n1 % 7 == 6)
  135.             fprintf(fp,"\n");
  136.       }
  137.    }
  138.    fprintf (fp,"\t}\n};\n\n");
  139.    fprintf (fp,"short int y3[50][51] = {\n\n");
  140.    for (a=0;a<50;a++){
  141.       if (a!=0)
  142.          fprintf(fp,"\t},\n\n");
  143.       fprintf(fp,"\t{\n");
  144.       for (n1=0;n1<51;n1++){
  145.          fprintf(fp,"\t%d",y3[a][n1]);
  146.          if (n1!=50)
  147.             fprintf(fp,",");
  148.          if (n1 % 7 == 6)
  149.             fprintf(fp,"\n");
  150.       }
  151.    }
  152.    fprintf (fp,"\t}\n};\n\n");
  153.    fclose(fp);
  154. }
  155.